package com.xh.bussiness.tms.controller;

import com.xh.bussiness.tms.bean.request.SaveOrUpdateStudentAttendRequest;
import com.xh.bussiness.tms.service.IStudentAttendService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.util.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Pitt Cheung
 * @date 2021/7/12 14:34
 */
@RestController
@RequestMapping("/studentAttend")
public class StudentAttendController {

    @Autowired
    private IStudentAttendService studentAttendService;


    @ApiOperation("获取班级学生考勤数据")
    @RequestMapping("/queryStudentAttendData")
    public AjaxResult queryStudentAttendData(String classId,String currId) {
        if (StringUtils.isEmpty(classId) || StringUtils.isEmpty(currId)) {
            return new AjaxResult(AjaxResultConstant.Result.ERROR, "参数错误");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, studentAttendService.queryStudentAttendData(classId, currId));
    }

    @ApiOperation("批量保存学生考勤数据")
    @RequestMapping("/batchSaveOrUpdateStudentAttend")
    public AjaxResult batchSaveOrUpdateStudentAttend(@RequestBody SaveOrUpdateStudentAttendRequest request) {
        String msg = studentAttendService.batchSaveOrUpdateStudentAttend(request);
        if (StringUtils.isEmpty(msg)) {
            return new AjaxResult(AjaxResultConstant.Result.SUCCESS);
        }
        return new AjaxResult(AjaxResultConstant.Result.ERROR);
    }

}
